home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- FxCDL v1.05 for FM TOWNS Copyright (C) 1994 by T.Shimomura
-
- for LSI C-86 Ver.3.30 試食版
-
- WHIPSの出力するCDLファイルの最後に付加される、
- 1A 0D 0A を削除する。
-
- ※このコードが付加されるのは、WHIPSのバグと思われる。
- このために、TownsシステムのCDプレイヤー(CD_PLAY.EXP)で
- 正常に登録が出来ない。(もしかしたらこっちのバグかも知れない)
- *********************************************************************/
-
- #undef DEBUG
- // #define DEBUG 1
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- #include "tspath.h"
-
- // プロトタイプ
- int main(int argc, char **argv);
-
- // メイン
- int main(int argc, char **argv)
- {
- int fh, fl;
- struct stat fstat;
- char c[3];
- char path[512];
- char drv[MAX_DRIVE];
- char dir[MAX_DIR];
- char fnm[MAX_FNAME];
- char ext[MAX_EXT];
-
- puts("FxCDL v1.05 for FM TOWNS "
- "Copyright (C) 1994 by T.Shimomura");
-
- if (argc < 2) {
- puts("Usage : fxcdl <path>");
- puts(" (ex.) fxcdl f:\\whips4\\whips4.cdl");
- return (0);
- }
-
- strcpy(path, argv[1]);
-
- // ディレクトリで指定されていたら、"whips4.cdl"を付加する。
- if (stat(path, &fstat) == 0 && fstat.st_mode & S_IFDIR)
- strcat(path, "\\whips4.cdl");
-
- // パス名解析
- splitPath(path, drv, dir, fnm, ext);
- // ファイル名が省略されていたら、"whips4"を付加する。
- if (*fnm == '\0') {
- strcpy(path, drv);
- strcat(path, dir);
- strcat(path, "whips4");
- strcat(path, ext);
- }
- // 拡張子が省略されていたら、".cdl"を付加する。
- if (*ext == '\0')
- strcat(path, ".cdl");
-
- printf("Target : \"%s\"\n", path);
-
- // ファイルオープン
- if ( (fh = open(path, O_RDWR | O_BINARY)) < 0) {
- puts("\aerror : file open failed.");
- return (1);
- }
-
- // 最後の3バイトへシーク
- if ( (fl = lseek(fh, -3, SEEK_END)) < 0) {
- puts("\aerror : file seek failed.");
- close(fh);
- return (1);
- }
-
- // 最後の3バイトを読む
- if (read(fh, c, 3) < 3) {
- puts("\aerror : file read failed.");
- close(fh);
- return (1);
- }
-
- // 最後の3バイトの照合
- if (c[0] == 0x1A && c[1] == 0x0D && c[2] == 0x0A) {
- if (chsize(fh, fl) < 0) {
- puts("\aerror : file resize failed.");
- close(fh);
- return (1);
- }
- }
-
- // ファイルクローズ
- if (close(fh) < 0) {
- puts("\aerror : file close failed.");
- return (1);
- }
- puts("success.");
-
- return (0);
- }
-